import Layout from '../layout'
import rout from './createAsyncRoutes'

const mapComponent = {
  'Layout': () => import('@/layout'),
  '@/views/wenhuahui/theater': () => import('@/views/wenhuahui/theater'),
  '@/views/wenhuahui/user/pu': () => import('@/views/wenhuahui/user/pu'),
  '@/views/wenhuahui/user/pu/a': () => import('@/views/wenhuahui/user/pu/a'),
  '@/views/wenhuahui/user/wen': () => import('@/views/wenhuahui/user/wen'),
  '@/views/wenhuahui/add_routes': () => import('@/views/add_routes'),
}

// console.log(rout, 5555555555)

function replaceComponent(rout) {

  // console.log(rout, 66666666666)
  if (Array.isArray(rout)) {
    rout.forEach(item => {

      if (item.component && typeof item.component == 'string') {
        // console.log(item.component, 4564564566)
        if (item.component === 'Layout') {
          item.component = Layout;
        } else {
          item.component = mapComponent[item.component] //mapComponentByComponentName(item.component)
        }

        let child = item.children
        if (Array.isArray(child) && child.length > 0) {
          replaceComponent(child)
        }
      }

    })

    // console.log(rout, 77777777777)
    return rout

  }
}

const asyncRoute = replaceComponent(rout)

export default asyncRoute
